<?php
namespace app\admin\logic;

class WorkStationMessageLogic extends BaseLogic {

    /**
     * 获取工位留言查询条件
     * @param $openid
     * @param $branchid
     * @param $floorid
     * @param $regionid
     * @param $number
     * @param $start_time
     * @param $end_time
     * @return array
     */
    public function get_search_wsm_maps($openid,$branchid,$floorid,$regionid,$number,$start_time,$end_time){
        $maps = [];

        if(!empty($openid)){
            $maps[] = ['openid','=',$openid];
        }
        if($branchid != -1){
            $f_maps = [];
            $f_maps[] = ['branchid','=',$branchid];
            $floorids = model('floor')->get_column($f_maps,'id');

            $r_maps = [];
            $r_maps[] = ['floorid','in',$floorids];
            $regionids = model('region')->get_column($r_maps,'id');

            $ws_maps = [];
            $ws_maps[] = ['regionid','in',$regionids];
            $wsids = model('work_station')->get_column($ws_maps,'id');

            $maps[] = ['wsid','in',$wsids];
        }
        if($floorid != -1){
            $r_maps = [];
            $r_maps[] = ['floorid','=',$floorid];
            $regionids = model('region')->get_column($r_maps,'id');

            $ws_maps = [];
            $ws_maps[] = ['regionid','in',$regionids];
            $wsids = model('work_station')->get_column($ws_maps,'id');

            $maps[] = ['wsid','in',$wsids];
        }
        if($regionid != -1){
            $ws_maps = [];
            $ws_maps[] = ['regionid','=',$regionid];
            $wsids = model('work_station')->get_column($ws_maps,'id');

            $maps[] = ['wsid','in',$wsids];
        }
        if(!empty($number)){
            $ws_maps = [];
            $ws_maps[] = ['number','=',$number];
            $wsids = model('work_station')->get_column($ws_maps,'id');

            $maps[] = ['wsid','in',$wsids];
        }
        if(!empty($start_time) && !empty($end_time)){
            $maps[] = ['c_time','between',[$start_time,$end_time]];
        }

        return $maps;
    }
}